//
//  RootViewController.m
//  UI06_homeWork讲解
//
//  Created by dllo on 16/1/13.
//  Copyright © 2016年 YYL. All rights reserved.
//

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSArray *arr = @[@"3", @"1", @"2", @"3", @"1"];
    
    UIScrollView *scorollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
    scorollView.delegate = self;
    
    for (int i = 0; i < 5; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, scorollView.frame.size.width, scorollView.frame.size.height)];
        
        UIScrollView *little = [[UIScrollView alloc] initWithFrame:CGRectMake(imageView.frame.size.width * i, 0, imageView.frame.size.width, imageView.frame.size.height)];
        
        imageView.image = [UIImage imageNamed:arr[i]];
        [little addSubview:imageView];
        [imageView release];
        
        little.delegate = self;
        little.minimumZoomScale = 0.5;
        little.maximumZoomScale = 2.0;
        
        
        [scorollView addSubview:little];
        [little release];
    }
    
    scorollView.contentSize = CGSizeMake(scorollView.frame.size.width * 5, 0);
    scorollView.contentOffset = CGPointMake(scorollView.frame.size.width, 0);
    
    scorollView.pagingEnabled = YES;
    scorollView.showsHorizontalScrollIndicator = NO;
    scorollView.bounces = NO;
    

    [self.view addSubview:scorollView];
    [scorollView release];



}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return [scrollView.subviews firstObject];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    
    if (scrollView.contentOffset.x / self.view.frame.size.width == 0) {
        scrollView.contentOffset = CGPointMake(scrollView.frame.size.width * 3, 0);
    }
    if (scrollView.contentOffset.x / self.view.frame.size.width == 4) {
        scrollView.contentOffset = CGPointMake(scrollView.frame.size.width, 0);
    }
    
    for (UIScrollView *little in scrollView.subviews) {
        if ([little isKindOfClass:[UIScrollView class]]) {
            little.zoomScale = 1;
        }
    }
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
